package com.mall.mapper;

import com.mall.pojo.GoodsCategoryPo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mall.vo.Node;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 类目表 Mapper 接口
 * </p>
 *
 * @author zhangshiqi
 * @since 2020-09-13
 */
public interface GoodsCategoryMapper extends BaseMapper<GoodsCategoryPo> {

    /**
     * 查询所有类目信息
     */
    @Select("select c.*,p.name parentName from goods_category c left join goods_category p on c.parentId=p.id")
    List<Map<String,Object>> findObjects();

    /**
     * 查询所有ztree节点信息
     */
    @Select("select id,name,parentId from goods_category")
    List<Node> findZTreeNodes();

    /**
     * 查询是否存在子类类目
     */
    @Select("select count(*) from goods_category where parentId=#{id}")
    int getChildCount(Integer id);

}
